package com.bugpool.leilema.tc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bugpool.leilema.tc.bean.entity.SysUser;
import com.bugpool.leilema.tc.bean.req.RoleUserReq;
import com.bugpool.leilema.tc.bean.req.UserReq;
import com.bugpool.leilema.tc.bean.res.UserRes;
import com.bugpool.leilema.tc.service.LoginService;
import com.bugpool.leilema.tc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @Description
 * @Date 2023/3/6 9:50
 * @Version 1.0
 **/
@RequestMapping("/user")
@RestController
@Api(tags = "用户控制器")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    @ApiOperation("用户列表")
    public Page<UserRes> list(UserReq userReq) {
        return userService.list(userReq);
    }


    @GetMapping("/{userId}")
    @ApiOperation("用户详情")
    public UserRes getUser(@PathVariable Long userId) {
        return userService.getUser(userId);
    }

    @PostMapping("/addUser")
    @ApiOperation("添加用户")
    public boolean addUser(@RequestBody SysUser sysUser) {
        return userService.addUser(sysUser);
    }

    @PutMapping("/updateUser")
    @ApiOperation("用户更新")
    public boolean updateUser(@RequestBody SysUser sysUser) {
        return userService.updateUser(sysUser);
    }


    @GetMapping("/{userId}/{status}")
    @ApiOperation("更改状态 启用禁用")
    public Boolean updateStatus(@PathVariable Long userId, @PathVariable String status) {
        return userService.updateStatus(userId, status);
    }

    @PutMapping("/userRole")
    @ApiOperation("更新用户角色关系")
    public boolean updateUserRole(@RequestBody RoleUserReq roleUserReq) {
        return userService.updateUserReq(roleUserReq);
    }

    @DeleteMapping("/{userIds}")
    @ApiOperation("删除用户")
    public boolean delUserByIds(@PathVariable List<Long> userIds) {
        return userService.delUserByIds(userIds);
    }
}
